// pages/nextstep/nextstep.js
const {
  get,
  post,
  postList
} = require('../../request/index')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data:{},
    hotList:[
      {
        label: '生产股审核',
        prop: 'auditMemberId',
        type: 'multiDropDown',
         sort:1,
        hidden: 'look',
        net: {
          url: '/app/asysrole/getAllMember',
          method: 'post',
          data: {
            mineId: true,

          },
          key: 'memberId',
          value: 'nickName'
        }
      },
      {
        label: '安全股审核',
        prop: 'auditMemberId',
        type: 'multiDropDown',
        sort:2,
        hidden: 'look',
        net: {
          url: '/app/asysrole/getAllMember',
          method: 'post',
          data: {
            mineId: true,

          },
          key: 'memberId',
          value: 'nickName'
        }
      },
      {
        label: '主要负责人审批',
        prop: 'auditMemberId',
        type: 'multiDropDown',
        sort:3,
        hidden: 'look',
        net: {
          url: '/app/asysrole/getAllMember',
          method: 'post',
          data: {
            mineId: true,

          },
          key: 'memberId',
          value: 'nickName'
        }
      },
     
     
     
    
     
    ],
    narr:[],
    prolist: wx.getStorageSync('prolist') == '' ? wx.getStorageSync('prolist') : JSON.parse(wx.getStorageSync('prolist')),
    options:{}  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
        let {prolist}    = this.data
        console.log(options);
     this.setData({
      options:JSON.parse(options.data)
     })
     post(`/app/processStep/getList`,{processType:"矿井主扇风机审批",mineId:prolist.mineId}).then(res=>{
         let list = []
      list =    res.data.list.map((item)=>{
        return {
          ...item,
          net: {
            url: '/app/asysrole/getAllMember',
            method: 'post',
            data: {
              mineId: true,
  
            },
            key: 'memberId',
            value: 'nickName'
           
          },  
          prop:""
        }
         })

         this.setData({
          hotList:list
         })
     })
  },
  change(e){
    let a = this.data.data
    let {narr,prolist} = this.data
    let obj = {}
    obj.applicantId = prolist.userid;
    obj.selectedUserId = e.detail
    
   obj.stepId = e.target.dataset.item.stepId
    let arr = []
   
      arr.push(obj)
  
      this.setData({
        narr:narr.concat(arr)
      })
     
    
    
  },

  sbtmit(){
    let {narr,options,prolist} = this.data
    let nArr =  narr.filter((currentValue, currentIndex, selfArr) =>{
      return selfArr.findIndex(x =>x.stepId === currentValue.stepId) === currentIndex
    });
    console.log(nArr);
    this.setData({  
      narr:nArr
    })
  // let f = JSON.stringify(nArr)
    if(narr.length==3){
      post('/app/approvalRecord/insert',{userSelectionList:nArr,...options,processType:'矿井主扇风机审批',mineId:prolist.mineId,applicantId:prolist.userid}).then(res=>{
        console.log(res);
         if(res.success){
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            duration: 1500,
            mask: true
          })
          wx.navigateBack({
            delta: 2
          })
         }
      })
    }else{
      console.log('提交不了啊');
    }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})